<template>
  <div>
    <el-table
      :data="emps"
      border
      stripe>
      <el-table-column
        align="left"
        type="selection"
        width="55">
      </el-table-column>
      <el-table-column
        align="left"
        label="姓名"
        prop="name"
        fixed
        width="120">
      </el-table-column>
      <el-table-column
        align="left"
        label="工号"
        prop="workID"
        width="120">
      </el-table-column>
      <el-table-column
        align="left"
        label="电子邮箱"
        prop="email"
        width="200">
      </el-table-column>
      <el-table-column
        align="left"
        label="电话"
        prop="phone"
        width="120">
      </el-table-column>
      <el-table-column
        align="left"
        label="所属部门"
        prop="department.name"
        width="120">
      </el-table-column>
      <el-table-column
        align="center"
        label="工资账套">
        <template slot-scope="scope">
          <el-tooltip placement="right" v-if="scope.row.salary.name">
            <div slot="content">
              <table>
                <tr>
                  <td>基本工资</td>
                  <td>{{scope.row.salary.basicSalary}}</td>
                </tr>
                <tr>
                  <td>交通补助</td>
                  <td>{{scope.row.salary.trafficSalary}}</td>
                </tr>
                <tr>
                  <td>午餐补助</td>
                  <td>{{scope.row.salary.lunchSalary}}</td>
                </tr>
                <tr>
                  <td>奖金</td>
                  <td>{{scope.row.salary.bounds}}</td>
                </tr>
                <tr>
                  <td>养老金比率</td>
                  <td>{{scope.row.salary.pensionPer}}</td>
                </tr>
                <tr>
                  <td>养老金基数</td>
                  <td>{{scope.row.salary.pensionBase}}</td>
                </tr>
                <tr>
                  <td>医疗保险比率</td>
                  <td>{{scope.row.salary.medicalPer}}</td>
                </tr>
                <tr>
                  <td>医疗保险基数</td>
                  <td>{{scope.row.salary.medicalBase}}</td>
                </tr>
                <tr>
                  <td>公积金比率</td>
                  <td>{{scope.row.salary.accumulationFundPer}}</td>
                </tr>
                <tr>
                  <td>公积金基数</td>
                  <td>{{scope.row.salary.accumulationFundBase}}</td>
                </tr>
              </table>
            </div>
            <el-tag>{{ scope.row.salary.name}}</el-tag>
          </el-tooltip>
          <el-tag v-else>暂未设置</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="操作">
        <template>
          <el-popover
            @show="showPop(scope.row.salary)"
            @hide="hidePop(scope.row)"
            placement="left"
            title="编辑工资账套"
            width="200"
            trigger="click"
            content="这是一段内容,这是一段内容,这是一段内容,这是一段内容。">
            <div>
              <template>
                <el-select v-model="currentSalary" placeholder="请选择">
                  <el-option
                    v-for="item in salaries"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
              </template>
            </div>
            <el-button slot="reference" type="danger">修改工资账套</el-button>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <div style="display: flex; justify-content: flex-end; margin-top: 5px;">
      <!-- 位置右对齐 -->
      <el-pagination
       background
       @current-change="currentChange"
       @size-change="sizeChange"
       layout="prev, pager, next, jumper, ->, total"
      :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default{
  name: 'SalSobCfg',
  data(){
    return{
      currentSalary: null,
      salaries: [],
      emps: [],
      currentPage: 1,
      size: 10,
      total: 0,
    }
  },
  mounted(){
    this.initEmps()
  },
  methods: {
    hidePop(data){
      if(this.currentSalary && this.currentSalary !== data.salary.id){//判断current是否存在,同时是否真的更新
        this.putRequest('/salary/sobcfg/?eid=' + data.id + '&sid=' + this.currentSalary).then(res => {
        if(res){
          this.initEmps()
        }
      })
      }
    },
    showPop(data){
      if(data)
        this.currentSalary = data.id//把select默认设置成员工默认工资账套
      else 
        this.currentSalary = null//没有data就等于空对象,就显示placeholder
    },
    initSalaries(){
      this.getRequest('/salary/sobcfg/salaries').then(res => {
        if(res){
          this.salaries = res
        }
      })
    },
    sizeChange(){
      this.size = size
      this.initEmps()
    },
    currentChange(){
      this.currentPage = page
      this.initEmps()
    },
    initEmps(){
      this.getRequest('/salary/sobcfg/?currentPage=' + this.currentPage + '&size=' + this.size).then(res => {
        if(res){
          this.emps = res.data
          this.total = res.total
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
